/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
   this file is part of rcssserver3D
   Fri May 9 2003
   Copyright (C) 2003 Koblenz University
   $Id$

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
// -*- C++ -*- generated by wxGlade 0.4 on Wed Jan  4 20:26:10 2006
#ifdef WIN32
#include <winsock2.h>
#endif

#ifndef MAINFRAME_H
#define MAINFRAME_H

#include <wx/wx.h>
#include <wx/image.h>
#include <wx/wxflatnotebook/wxflatnotebook.h>
#include <wx/wxscintilla.h>
#include "constants.h"
#include "sparktree.h"
#include "propertylist.h"
#include <oxygen/sceneserver/scenedict.h>

class SparkGLCanvas;
class SparkContextEvent;

namespace oxygen
{
    class SimulationServer;
}

// begin wxGlade: ::dependencies
#include <wx/splitter.h>
#include <wx/listctrl.h>
#include <wx/statline.h>
#include <wx/treectrl.h>
// end wxGlade

class mainframe: public wxFrame {
public:
    // begin wxGlade: mainframe::ids
    // end wxGlade

    mainframe(wxWindow* parent, int id, const wxString& title, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE);
    virtual ~mainframe();

private:
    // begin wxGlade: mainframe::methods
    void set_properties();
    void do_layout();
    // end wxGlade

protected:
    /** start and run simulation */
    void StartSimulation(bool singleStep);

    /** pause a running simulation */
    void PauseSimulation();

    /** pause and reset the running simulation */
    void ResetSimulation();

    /** go through one simulation cycle with the given time step */
    void AdvanceSimulation(boost::shared_ptr<oxygen::SimulationServer>& sim, float tDeltaSec);

    /** prepare to start the simulation */
    void InitSimulation(boost::shared_ptr<oxygen::SimulationServer>& sim);

    /** shut down the simulation */
    void DoneSimulation(boost::shared_ptr<oxygen::SimulationServer>& sim);

    void OnUpdateStartSimulation(wxUpdateUIEvent& event);
    void OnStartSimulation(wxCommandEvent& event);

    void OnUpdateStepSimulation(wxUpdateUIEvent& event);
    void OnStepSimulation(wxCommandEvent& event);

    void OnUpdatePauseSimulation(wxUpdateUIEvent& event);
    void OnPauseSimulation(wxCommandEvent& event);

    void OnViewTree(wxCommandEvent& event);
    void OnUpdateViewTree(wxUpdateUIEvent& event);

    void OnViewLog(wxCommandEvent& event);
    void OnUpdateViewLog(wxUpdateUIEvent& event);

    void OnFileNew(wxCommandEvent& event);

    void OnFileOpen(wxCommandEvent& event);
    void OnUpdateFileOpen(wxUpdateUIEvent& event);

    bool SaveFileAs(wxScintilla* edit);
    void OnFileSaveAs(wxCommandEvent& event);

    bool SaveFile(wxScintilla* edit);
    void OnFileSave(wxCommandEvent& event);
    void OnUpdateFileSave(wxUpdateUIEvent& event);

    void OnFileReload(wxCommandEvent& event);
    void OnUpdateFileReload(wxUpdateUIEvent& event);

    void OnAgentOpen(wxCommandEvent& event);

    void OnHelpAbout(wxCommandEvent& event);

    void OnContextProperties(wxCommandEvent& event);
    void OnContextKinematic(wxCommandEvent& event);
    void OnContextEditSource(wxCommandEvent& event);
    void OnContextCopyFileName(wxCommandEvent& event);
    void OnContextCopyPath(wxCommandEvent& event);

    void OnLogClear(wxCommandEvent& event);
    void OnLogCopy(wxCommandEvent& event);
    void OnLogChannel(wxCommandEvent& event);

    void OnExit(wxCommandEvent& event);
    void OnClose( wxCloseEvent& event );

    void OnLogTimer(wxTimerEvent& event);
    void OnFPSTimer(wxTimerEvent& event);

    /** appends the accumulated log buffer to the log window pane */
    void UpdateLogWindow();

    /** returns true iff its safe to close this frame now */
    bool CanClose();

    /** returns the current simulation state */
    ESimState GetSimState() const;

    /** update the title of the window */
    void UpdateTitle();

    /** resets the current simulation and starts a new one from the
        given script file
    */
    bool OpenSimulation(const wxString& fname);

    /** Print the current simulation state on the toolbar */
    void PrintSimState();

    void UpdateLogChannelState();
    void InitTreeNodeProperties();
    void SelectCanvasTab();
    void SaveModified();

    void OnTreeItemExpanding(wxTreeEvent& event);
    void OnTreeSelChanged(wxTreeEvent& event);
    void OnTreeItemActivated(wxTreeEvent& event);
    void OnTreeItemRightClick(wxTreeEvent& event);

    void OnTabStartScript(wxCommandEvent& event);
    void OnTabCloseOther(wxCommandEvent& event);
    void OnTabClose(wxCommandEvent& event);

    void OnTabClosing(wxFlatNotebookEvent& event);
    void OnTabChanged(wxFlatNotebookEvent& event);
    void OnTabContextMenu(wxFlatNotebookEvent& event);

    void OnUpdateEditCommand(wxUpdateUIEvent& event);
    void OnEditCommand(wxCommandEvent& event);
    void OnEditSavePointReached(wxScintillaEvent& event);
    void OnEditSavePointLeft(wxScintillaEvent& event);

    void OnSparkContext(SparkContextEvent& event);

    void SplitHor();
    void SplitVert();

    /** refresh the contents of all open property windows */
    void RefreshProperties();

    /** updated any cached references */
    void UpdateCached();

    /** edit the given file starting at the given line */
    void EditFile(const wxString& fname, int line);

    /** lookup the FileRef for the context node */
    const oxygen::SceneDict::FileRef* GetContextFileRef();

    /** copy the given string to the sytem clipboard */
    void CopyToClipboard(const wxString& str) const;

protected:
    // begin wxGlade: mainframe::attributes
    wxMenuBar* MainFrame_menubar;
    wxStatusBar* MainFrame_statusbar;
    wxListCtrl* mCtrPropList;
    wxPanel* window_1_pane_1;
    wxTreeCtrl* mCtrTree;
    wxPanel* window_1_pane_2;
    wxSplitterWindow* window_1;
    wxPanel* mLeftPane;
    wxFlatNotebook* mCtrNotebook;
    wxPanel* mTopPane;
    wxTextCtrl* mCtrLog;
    wxButton* button_2;
    wxButton* button_3;
    wxStaticLine* static_line_1;
    wxStaticText* label_2;
    wxCheckBox* mCtrLogChannelDebug;
    wxCheckBox* mCtrLogChannelNormal;
    wxCheckBox* mCtrLogChannelWarning;
    wxCheckBox* mCtrLogChannelError;
    wxPanel* mBottomPane;
    wxSplitterWindow* mCtrHorSplitter;
    wxPanel* mRightPane;
    wxSplitterWindow* mCtrVertSplitter;
    // end wxGlade

protected:
    wxTimer mTimer;

    //! simulation time of the last static FPS controller update
    float mLastFPSUpdate;
    wxTimer mFPSTimer;

    wxToolBar* mToolBar;
    wxTextCtrl* mSimState;

    SparkTree mSparkTree;
    PropertyList mPropList;

    int mLastHorSashPosition;
    int mLastVertSashPosition;

    SparkGLCanvas* mCanvas;

    DECLARE_EVENT_TABLE()
}; // wxGlade: end class

#endif // MAINFRAME_H
